<script>
import axios from 'axios'
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router'; // 引入路由
import router from "@/router/index.js"

export function IsLoginIn(num = 1) {
    // const router = useRouter();
    const token = localStorage.getItem('userToken');
    if (token != null) {
        axios
            .post('/api/checkLogin', {}, {
                headers: {
                    'HOSHINO_T_KK': localStorage.getItem('userToken'),
                }
            })
            .then(response => {
                console.log(response);
                if (response.data.data == 1) {
                    if (num == 0) {
                        // console.log(num);
                        router.push('/');
                    }
                } else {
                    if (num == 1) {
                        // console.log(num);
                        router.push('/login');
                    }
                }
            })
            .catch(function (error) { // 请求失败处理
                console.log(error);
            });
    }
    else {
        router.push('/login');
    }
}

export function Revoke() {
    // const router = useRouter();

    axios
        .post('/api/user/revoke', {}, {
            headers: {
                'HOSHINO_T_KK': localStorage.getItem('userToken'),
            }
        })
        .then(response => {
            console.log(response);
            router.push('/');

        })
        .catch(function (error) { // 请求失败处理
            console.log(error);
        });
}
</script>
